﻿using System;
using Notoric.Gui.Windows;
using LukasKopenec.LocalizationSupport;

namespace Notoric.Gui.Commands
{
    /// <summary>
    /// Implements a command for creating a new project.
    /// </summary>
    public class NewProjectCommand : RibbonCommand
    {
        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="NewProjectCommand"/> class.
        /// </summary>
        /// <param name="mainWindow">
        /// <para>
        /// Type: <see cref="MainWindow"/>
        /// </para>
        /// <para>
        /// The main application window.
        /// </para>
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="mainWindow"/> is <see langword="null"/>.
        /// </exception>
        public NewProjectCommand(MainWindow mainWindow)
            : base(mainWindow)
        {
        }

        #endregion

        #region ICommand Members

        /// <inheritdoc/>
        public override bool CanExecute(object parameter)
        {
            return true;
        }

        /// <inheritdoc/>
        public override void Execute(object parameter)
        {
            if (ApplicationWindow.ProjectExplorer.Projects.Count > 0)
                ApplicationWindow.CloseCmd.Execute(null);

            if (ApplicationWindow.ProjectExplorer.Projects.Count > 0)
                return;

            var project = ViewModel.Elements.Project.CreateNew();
            project.Name = (string)LocalizationManager.GetValue("Application.NewProjectName");
            ApplicationWindow.ProjectExplorer.Projects.Add(project);
            ViewModel.ProjectExplorerCommands.RenameCommand.Execute(ApplicationWindow.ProjectExplorer.Projects[0], null);
            project.IsExpanded = true;
        }

        #endregion
    }
}
